package org.lilystudio.veryftp.dao.impl;

import org.hibernate.ScrollMode;
import org.hibernate.ScrollableResults;
import org.hibernate.criterion.Restrictions;
import org.hibernate.Transaction;

import org.hibernate.search.FullTextSession;
import org.lilystudio.veryftp.dao.TempDao;
import org.lilystudio.veryftp.enumeration.IndexState;
import org.lilystudio.veryftp.model.FTPFile;


/**
 * 例子而已，并非要取代原来的DAO
 * 总之DAO里需要把获得的东西保存在fullTextSession，保存在session中的对象，没法进行索引
 * 
 * @author fnight
 *
 */
public class TempDaoImpl implements TempDao{
	
	private FullTextSession fullTextSession;
	
	private ScrollableResults results;
	
	
	public FullTextSession getFullTextSession() {
		return fullTextSession;
	}
	public void setFullTextSession(FullTextSession fullTextSession) {
		this.fullTextSession = fullTextSession;
		
	}

	public FTPFile getFile() {	
		return (FTPFile)results.get(0);
	}

	public void getFiles(IndexState indexState) {
		// TODO Auto-generated method stub
		
		results=fullTextSession.createCriteria(FTPFile.class)
					.add(
							Restrictions.eq("fileState",indexState.toInteger())
						)
					.scroll(ScrollMode.FORWARD_ONLY);
		
	}

	public boolean hasNext() {
		// TODO Auto-generated method stub
		return results.next();
	}
	public Transaction getTransaction(){
		return fullTextSession.getTransaction();
	}

}
